package object_;

import java.io.*;

public class Test1 {
    public static void main(String[] args) {
        Cat cat = new Cat("小黄", 5);//
        int year=2025;
        String path="D:\\javacode\\javacode\\IO_1\\cat.dat";//写入路径
        ObjectOutputStream objectInputStream=null;
        try {
            objectInputStream=new ObjectOutputStream(new FileOutputStream(path));
            objectInputStream.writeObject(cat);//写入一个Cat对象
            objectInputStream.writeInt(year);//写入一个int型整数

        } catch (IOException e) {
            throw new RuntimeException(e);
        }finally {
            //关闭流
            try {
                if (objectInputStream!=null) {
                    objectInputStream.close();
                }
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

    }
}

class Cat implements Serializable {
    private String name;
    private int age;

    public Cat(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Cat{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}